package com.hqy.product.controller;


import com.hqy.product.dto.*;
import com.hqy.product.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "/api/item")
public class ItemController {
    @Autowired
    private ItemService itemService;

    /**
     * 查询商品的详细信息
     * @param skuId
     * @return
     */
    @GetMapping(value = "/getSkuInfo/{skuId}")
    public SkuInfo getSkuInfo(@PathVariable(value = "skuId") Long skuId){
        return itemService.getSkuInfo(skuId);
    }

    /**
     * 根据三级分类查询一级二级三级分类的信息
     * @param c3Id
     * @return
     */
    @GetMapping(value = "/getCategory/{c3Id}")
    public BaseCategoryView getCategory(@PathVariable(value = "c3Id") Long c3Id){
        return itemService.getCategory(c3Id);
    }

    /**
     * 根据sku的id查询图片列表
     * @param skuId
     * @return
     */
    @GetMapping(value = "/getSkuImage/{skuId}")
    public List<SkuImage> getSkuImage(@PathVariable(value = "skuId") Long skuId){
        return itemService.getSkuImage(skuId);
    }

    /**
     * 获取商品的价格
     * @param skuId
     * @return
     */
    @GetMapping(value = "/getPrice/{skuId}")
    public BigDecimal getPrice(@PathVariable(value = "skuId") Long skuId){
        return itemService.getPrice(skuId);
    }

    /**
     * 查询商品详情页使用的展示销售属性的信息,并且标识出当前的sku的销售属性值是哪个
     * @param skuId
     * @param spuId
     * @return
     */
    @GetMapping(value = "/getSaleAttrBySkuIdAndSpuId/{skuId}/{spuId}")
    public List<SpuSaleAttr> getSaleAttrBySkuIdAndSpuId(@PathVariable(value = "skuId") Long skuId,
                                                        @PathVariable(value = "spuId") Long spuId){
        return itemService.getSaleAttrBySkuIdAndSpuId(skuId, spuId);
    }

    /**
     * 获取指定spu下的所有sku的id和销售属性值的键值对
     *
     * @param spuId
     * @return
     */
    @GetMapping(value = "/getSkuKeyAndValues/{spuId}")
    public Map getSkuKeyAndValues(@PathVariable(value = "spuId") Long spuId){
        return itemService.getSkuKeyAndValues(spuId);
    }

    /**
     * 获取首页的分类的信息
     * @return
     */
    @GetMapping(value = "/getIndexCategory")
    public GmallResult getIndexCategory(){
        return GmallResult.ok(itemService.getIndexCategory());
    }

}
